extends Control


var TscnColumn = preload("res://tool/page/conditions/ConditionsColumn.tscn")


var conditions = [
	{"config":"{\"gym\": [-1], \"drama_id\": [21]}","id":1,"name":"speedShoes","remark":"极速鞋子，各个地区使用权限配置"},
	{"config":"{\"gym\": [-1], \"drama_id\": [27]}","id":2,"name":"kettle","remark":"水浒，各个地区的使用配置"},
	{"config":"{\"gym\": [-1], \"drama_id\": [215]}","id":3,"name":"fishLevel1","remark":"普通鱼竿配置1"},
	{"config":"{\"gym\": [-1], \"drama_id\": [5]}","id":4,"name":"fishLevel2","remark":"普通鱼竿配置2，这个是预留的注意"},
	{"config":"{\"gym\": [-1], \"drama_id\": [217]}","id":5,"name":"fishLevel3","remark":"普通鱼竿配置3"},
	{"config":"{\"gym\": [-1], \"drama_id\": [218]}","id":6,"name":"fishLevel4","remark":"普通鱼竿配置4 "},
	{"config":"{\"gym\": [2], \"drama_id\": [5]}","id":7,"name":"bike","remark":"自行车使用权限"},
	{"config":"{\"gym\": [1], \"drama_id\": [5]}","id":8,"name":"skillCut","remark":"秘籍居合劈 使用权限，"},
	{"config":"{\"gym\": [2], \"drama_id\": [41]}","id":9,"name":"skillFlash","remark":"秘籍闪光,使用权限"},
	{"config":"{\"gym\": [3], \"drama_id\": [5]}","id":10,"name":"skillRockSmash","remark":"秘籍碎岩，使用权限"},
	{"config":"{\"gym\": [4], \"drama_id\": [5]}","id":11,"name":"skillStrength","remark":"秘籍怪力,使用权限"},
	{"config":"{\"gym\": [5], \"drama_id\": [5]}","id":12,"name":"skillSurf","remark":"秘籍冲浪,使用权限"},
	{"config":"{\"gym\": [6], \"drama_id\": [5]}","id":13,"name":"skillFly","remark":"秘籍飞翔，使用权限"},
	{"config":"{\"gym\": [7], \"drama_id\": [123]}","id":14,"name":"skillDive","remark":"秘籍潜水，使用权限"},
	{"config":"{\"gym\": [8], \"drama_id\": [132]}","id":15,"name":"skillWaterfall","remark":"秘籍攀瀑，使用权限"},
	{"config":"{\"gym\": [8], \"drama_id\": [5]}","id":16,"name":"skillTeleport","remark":"瞬间移动，使用权限"},
	{"config":"{\"gym\": [-1], \"drama_id\": [-1]}","id":17,"name":"skillDig","remark":"挖洞，使用权限"},
]
# gym = -1 表示有权限，不写表示没有
# drama_id = [-1]，表示有权限，不写表示没有
var map_prop = {
	"speedShoes":"极速鞋子",
	"kettle":"水壶",
	"fishLevel1":"普通鱼竿1",
	"fishLevel2":"普通鱼竿2",
	"fishLevel3":"普通鱼竿3",
	"fishLevel4":"普通鱼竿4",
	"bike":"自行车",
	"skillCut":"秘籍居合劈",
	"skillFlash":"秘籍闪光",
	"skillRockSmash":"秘籍碎岩",
	"skillStrength":"秘籍怪力",
	"skillSurf":"秘籍冲浪",
	"skillFly":"秘籍飞翔",
	"skillDive":"秘籍潜水",
	"skillWaterfall":"秘籍攀瀑",
	"skillTeleport":"瞬间移动",
	"skillDig":"挖洞",
}

# 启动的时候检测下有没有配置文件，如果没有就 马上创建一个默认的配置文件在本地
func _ready():
	var list = DataSource.get_data_list(DataSource.conditions)
	for item in map_prop.keys():
		# 如果有
		var con = false
		for temp in list: 
			if temp["name"] == item: 
				con = true
				break
		if con: continue
		# 没有就插入一条默认值进去
		var data = {
			"config":"{\"gym\": [], \"drama_id\": []}",
			"name":item,
			"remark":map_prop[item]
		}
		DataSource.add_data(DataSource.conditions,data)
		pass
	state_update()
func state_update():
	update_list(DataSource.get_data_list(DataSource.conditions))
	


func update_list(list):
	var box = $table/ScrollContainer/VBoxContainer
	
	for child in box.get_children():
		child.queue_free()
		
	for data in list:
		var ui_item = TscnColumn.instance()
		ui_item.set_data(data)
		box.add_child(ui_item)
		
		ui_item.connect("edit", self, "_on_edit")

func _on_edit(data):
	var ui = MainTool.getUILayer().add_ui("res://tool/page/conditions/ConditionsModal.tscn", 0, false)
	ui.set_edit_data(data)
	ui.connect("close", self, "state_update")
